package com.ff.discounts.component.main
import androidx.lifecycle.ViewModelProvider
import com.angcyo.tablayout.delegate2.ViewPager2Delegate
import com.ff.discounts.R
import com.ff.discounts.databinding.ActivityMainBinding
import com.ff.discounts.databinding.ItemTabBinding
import com.qmuiteam.qmui.util.QMUIStatusBarHelper

class MainActivity : com.ff.discounts.activity.BaseViewModelActivity<ActivityMainBinding>() {
    private lateinit var viewModel: MainViewModel

    override fun initViews() {
        super.initViews()
        // 设置沉浸式状态栏
        QMUIStatusBarHelper.translucent(this)
    }

    override fun initDatum() {
        super.initDatum()

        viewModel = ViewModelProvider(this)[MainViewModel::class.java]

        //滚动控件
        binding.pager.apply {
            offscreenPageLimit = indicatorTitles.size
            adapter = MainAdapter(hostActivity, indicatorTitles.size)
            isUserInputEnabled = false
        }


        // 底部tab
        for (i in indicatorTitles.indices) {
            ItemTabBinding.inflate(layoutInflater).apply {
                content.setText(indicatorTitles[i])
                icon.setImageResource(indicatorIcons[i])
                binding.indicator.addView(root)
            }
        }
        ViewPager2Delegate.install(binding.pager,binding.indicator,false)
        viewModel.loadMore()
    }

    override fun initListeners() {
        super.initListeners()

    }

    companion object{
        // 底部tab
        private val indicatorTitles =
            intArrayOf(
                R.string.follow,
                R.string.square,
                R.string.me
            )

        private val indicatorIcons = intArrayOf(
            R.drawable.selector_tab_home,
            R.drawable.selector_tab_charge,
            R.drawable.selector_tab_me
        )
    }
}